/**
 * 计算行列式，因为规模极小，直接递归即可。
 * 
 */
#include <bits/stdc++.h>
using namespace std;
#include <bits/extc++.h>
using namespace __gnu_pbds;

using llt = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vll = vector<llt>;

const vector<vll> f(const vector<vll> & a, int c){
    int n = a.size() - 1;
    vector<vll> ret(n, vll(n, 0));
    for(int i=0;i<n;++i){
        const auto & row = a[i + 1];
        for(int j=0;j<c;++j){
            ret[i][j] = row[j];
        }
        for(int j=c+1;j<=n;++j){
            ret[i][j - 1] = row[j];
        }
    }
    return ret;
}

llt calc(const vector<vll> & a){
    if(a.size() == 1) return a[0][0];

    llt ans = 0;
    int n = a.size();
    llt k = 1;
    for(int i=0;i<n;++i){
        ans += k * a[0][i] * calc(f(a, i));
        k *= -1;
    }
    return ans;
}

int N, M;
vector<vll> A;

void work(){ 
    cin >> N >> M;
    A.assign(N, vll(M, 0));
    for(auto & a : A)for(auto & i : a)cin >> i;

    llt ans = 0x3F4F5F6F7F8F9F;
    for(int i=0;i<min(N, M);++i){
        vector<vll> tmp(i + 1, vll(i + 1, 0));
        for(int x=0;x<=i;++x){
            copy(A[x].begin(), A[x].begin() + i + 1, tmp[x].begin());
        }

        auto tt = calc(tmp);
        ans = min(ans, tt);
    }
    if(N != M) ans = min(ans, 0LL);
    cout << ans << endl;
	return;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);	
    int nofkase = 1;
	// cin >> nofkase;
	while(nofkase--) work();
	return 0;
}